package java_class_work.week08.internet.sendIntDemo;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Tiam
 * @Date 2022/11/3 21:35
 * @Description:
 */
public class Receive implements Runnable {
    private Socket socket;
    Map<Socket,String> map = new HashMap<>();

    public Receive(Socket socket) {
        this.socket = socket;
    }


    public void receive() {
        try {
            InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream();

            while (true) {
                byte read = (byte) inputStream.read();
                System.out.print("服务端接收的指令: " + read );
                outputStream.write(read);

                byte[] bytes = new byte[1024];
                int read1 = inputStream.read(bytes);
                System.out.println("【" + new String(bytes, 0, read1) + "】");
                outputStream.write(bytes, 0, read1);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @Override
    public void run() {
        receive();
    }
}
